package com.mdc.mansion.web.modules.pay.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.pay.entity.RestaurantOrderPayBack;
import com.mdc.mansion.core.modules.pay.RestaurantOrderPayBackService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 菜品接收设置Controller
 * @author xizf
 * @version 2018-08-10
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/restaurantOrderPayBack")
public class RestaurantOrderPayBackController extends BaseController {

	@Autowired
	private RestaurantOrderPayBackService restaurantOrderPayBackService;
	
	@ModelAttribute
	public RestaurantOrderPayBack get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return restaurantOrderPayBackService.get(id);
		}else{
			return new RestaurantOrderPayBack();
		}
	}
	
	@RequiresPermissions("pay:restaurantOrderPayBack:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(RestaurantOrderPayBack restaurantOrderPayBack) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<RestaurantOrderPayBack> page = restaurantOrderPayBackService.findPage(restaurantOrderPayBack);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/pay/restaurantOrderPayBackList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("pay:restaurantOrderPayBack:view")
	@RequestMapping(value = "form")
	public ModelAndView form(RestaurantOrderPayBack restaurantOrderPayBack) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("restaurantOrderPayBack", restaurantOrderPayBack);
		return new ModelAndView("modules/pay/restaurantOrderPayBackForm",model);
	}
	

	@RequiresPermissions("pay:restaurantOrderPayBack:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(RestaurantOrderPayBack restaurantOrderPayBack,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		restaurantOrderPayBack.setUpdateBy(u);
		if (StringUtils.isNotBlank(restaurantOrderPayBack.getId())){
			restaurantOrderPayBackService.updateSelective(restaurantOrderPayBack);
		}else{
			restaurantOrderPayBack.setCreateBy(u);
			restaurantOrderPayBackService.save(restaurantOrderPayBack);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("pay:restaurantOrderPayBack:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(RestaurantOrderPayBack restaurantOrderPayBack,RedirectAttributes redirectAttributes) {
		restaurantOrderPayBackService.delete(restaurantOrderPayBack);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
